/*
 * Create a Hashmap to store doctors;
 * Create menu for user to choose options
 */

/**
 *
 * @author luan
 */
import java.util.*;

public class doctortest {
    public static void main(String args[])
    {
        int choose=0;
        Scanner sc=new Scanner(System.in);
        HashMap<String,doctor> DoctorHashMap=new HashMap();
        while(true)
        {
            System.out.println("1/ Register a doctor ");
            System.out.println("2/ Search and Display a doctor");
            System.out.println("3/ Publish the entire list");
            System.out.println("4/ Exit");
            try{
            System.out.println("\n\n\nEnter Your choose: ");
            choose=sc.nextInt();}
            catch(Exception ex)
            {
                System.out.println("Must be a digit.....");
            }
            switch (choose)
            {
                case 1:
                {
                    String code,name,dept;
                    int year=0;
                    System.out.println("Code: ");
                    code=sc.next();
                    System.out.println("Name: ");
                    name=sc.next();
                    System.out.println("Dept: ");
                    dept=sc.next();
                    try{
                    System.out.println("Year worked");
                    year=sc.nextInt();
                    }
                    catch(Exception ex)
                    {
                        System.out.println("Must be a digit.....");
                    }
                    doctor Dc=new doctor(code,name,dept,year);
                    DoctorHashMap.put(code,Dc);
                    break;
                }
                case 2:
                {
                  String search;
                  System.out.println("Input code of Doctor to search: ");
                  search=sc.next();
                  doctor dr=(doctor)DoctorHashMap.get(search);
                  if(dr!=null)
                  {
                  System.out.println(dr.toString());
                  }
                  else
                      System.out.println("Code not found....");
                  break;
                }
                case 3:
                {
                    System.out.println("The list has total: "+DoctorHashMap.size()+" Doctor");
                    Set set=DoctorHashMap.keySet();
                    Iterator iterator= set.iterator();
                    while(iterator.hasNext())
                    {
                        System.out.println(DoctorHashMap.get(iterator.next()).toString());
                    }
                    break;
                }
                case 4:
                {
                    System.out.println("Program Exit Successfully: ");
                    System.exit(1);
                }
                default:
                    System.out.println("Wrong choosen, choose again....");
                    break;
            }
        }
    }
}
